package com.higgins.eventtracking.client.health.overview;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.higgins.eventtracking.client.health.action.DailyTab;
import com.higgins.eventtracking.client.health.components.HealthOverviewChart;
import com.higgins.eventtracking.client.health.components.HealthOverviewChartListBox;
import com.higgins.eventtracking.client.health.overview.AchievementTab;
import com.higgins.eventtracking.client.health.overview.DigestionTab;
import com.higgins.eventtracking.client.health.overview.FrameOfMindTab;
import com.higgins.eventtracking.client.health.overview.GoalsTab;
import com.higgins.eventtracking.client.health.overview.HygieneTab;
import com.higgins.eventtracking.client.health.overview.NegativeTab;
import com.higgins.eventtracking.client.health.overview.HourlyTab;
import com.higgins.eventtracking.client.health.overview.WellBeingTab;

public class TimetableTab extends VerticalPanel	{
	private TabPanel tabPanel = new TabPanel();
	private YearlyTab yearlyTab = new YearlyTab();
	private MonthlyTab monthlyTab = new MonthlyTab();
	private WeeklyTab weeklyTab = new WeeklyTab();
	private DailyTab dailyTab = new DailyTab();
	private HourlyTab hourlyTab = new HourlyTab();
	private boolean firstRun = true;
	
	public TimetableTab()	{	
		
	}
	
	public void addGoalsTab()	{
		addTabs();
	}
	public void update()	{
		if (firstRun)	
			initialise();
	}
	public void initialise()	{
		populateTabPanel();
		firstRun = false;
	}
	public void populateTabPanel()	{
		addTabs();
		add(tabPanel);
	}
	private void addTabs()	{
		tabPanel.add(yearlyTab, "Yearly");
		tabPanel.add(monthlyTab, "Monthly");
		tabPanel.add(weeklyTab, "Weekly");
		tabPanel.add(dailyTab, "Daily");
		tabPanel.add(hourlyTab, "Hourly");
		yearlyTab.update();
		tabPanel.selectTab(0);
		tabPanel.addSelectionHandler(createSelectionHandler());		
	}
	public SelectionHandler<Integer> createSelectionHandler()	{
		SelectionHandler<Integer> selectionHandler = new SelectionHandler<Integer>() {
	        @Override
	        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
	            if (integerSelectionEvent.getSelectedItem() == 0)	{
	            	yearlyTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 1)	{
	            	monthlyTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 2)	{
	            	weeklyTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 3)	{
	            	dailyTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 4)	{
	            	hourlyTab.update();
	            }
	        }
		};
		return selectionHandler;
	}

}
